package sis.ra.display;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;

public class Display {

	/**
	 * display the entities in the text documents using different color to visualize them
	 */
	public static void main(String[] args) {
		String content = "Google Inc. is an American public corporation, earning revenue from advertising related to its Internet search, e-mail, online mapping, office productivity, social networking, and video sharing services as well as selling advertising-free versions of the same technologies. ";
		String newcontent=content;
		HashMap<Integer, String> terms = new HashMap<Integer, String> ();
		terms.put(0, "Google");
		terms.put(12, "is");
		terms.put(18, "American");	
		terms.put(82, "Internet");
		
		Object[]   key   =     terms.keySet().toArray();  
	    Arrays.sort(key);  	    
	    Integer position = Integer.parseInt(key[0].toString());
	    
	    Integer start = 0;
	    Integer end = position+terms.get(position).length();
	    
	    newcontent=content.substring(start,position)+"<span style=\"color:orange\">" + content.substring(position,end) + "</span>" ;
	    System.out.println(newcontent);
	    Integer add = terms.get(position).length();
	    
	    for (int i = 1;i < key.length; i++)   {
	    	start = end;
	    	position = Integer.parseInt(key[i].toString());
	    	end = position+terms.get(position).length();
	    	
	    	String term = terms.get(key[i]);
	    	
	    	System.out.println(position +"\t"+ term );
	    	
	    	newcontent = newcontent+content.substring(start,position)+"<span style=\"color:orange\">"+
			  content.substring(position, position+terms.get(position).length()) + "</span>" ;
	    	
	    	add = add+ terms.get(position).length();
			System.out.println(newcontent);
	    }	
	    
	    newcontent = newcontent + content.substring(end);
	    
	    System.out.println(newcontent);
	}

}
